package com.bdqn.service.impl;

import com.bdqn.mapper.HisPatientMapper;
import com.bdqn.mapper.HisRegistrationMapper;
import com.bdqn.pojo.HisPatient;
import com.bdqn.pojo.HisRegistration;
import com.bdqn.service.HisRegistrationService;
import com.bdqn.util.RandomUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

@Service
public class HisRegistrationServiceImpl implements HisRegistrationService {
    @Autowired
    HisRegistrationMapper hisRegistrationMapper;
    @Autowired
    HisPatientMapper hisPatientMapper;

    @Autowired
    RandomUtil randomUtil;

    @Override
    public int addHisRegistration(HisRegistration hisRegistration) {
        String registrationId =randomUtil.randomRegistration();
        hisRegistration.setRegId(registrationId);
        System.out.println("aaaaa:"+registrationId);
        String visitDate = hisRegistration.getCreateTime();
        if (hisRegistration.getSchedulingType().equals("1")){
            hisRegistration.setRegItemAmount("20.00");
        } else if (hisRegistration.getSchedulingType().equals("2")) {
            hisRegistration.setRegItemAmount("30.00");
        } else if (hisRegistration.getSchedulingType().equals("3")) {
            hisRegistration.setRegItemAmount("25.00");
        } else if (hisRegistration.getSchedulingType().equals("4")) {
            hisRegistration.setRegItemAmount("35.00");
        } else if (hisRegistration.getSchedulingType().equals("5")) {
            hisRegistration.setRegItemAmount("10.00");
        } else if (hisRegistration.getSchedulingType().equals("6")) {
            hisRegistration.setRegItemAmount("15.00");
        }
        hisRegistration.setVisitDate(visitDate);
        return hisRegistrationMapper.addHisRegistration(hisRegistration);
    }

    @Override
    public PageInfo<HisRegistration> getAll(int pageNum, int pageSize, String deptId, String name, String schedulingType, String subsectionType, String createTime) {
        PageHelper.startPage(pageNum, pageSize);
        List<HisRegistration> registrationList = hisRegistrationMapper.FuzzyQueryForPatients(deptId,name,schedulingType,subsectionType,createTime);
        PageInfo<HisRegistration> pageInfo = new PageInfo<>(registrationList);
        return pageInfo;
    }

    @Override
    public PageInfo<HisRegistration> page(int pageNum, int pageSize, String doctorName, String visitDate) {
        PageHelper.startPage(pageNum,pageSize);
        List<HisRegistration> list=hisRegistrationMapper.selectAll(doctorName,visitDate);
        PageInfo<HisRegistration> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<HisRegistration> page2(int pageNum, int pageSize, String doctorName) {
        PageHelper.startPage(pageNum,pageSize);
        List<HisRegistration> list=hisRegistrationMapper.selectAll2(doctorName);
        PageInfo<HisRegistration> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int chargeHisRegistration(String id) {
        return hisRegistrationMapper.chargeHisRegistration(id);
    }

    @Override
    public int refundHisRegistration(String id) {
        return hisRegistrationMapper.refundHisRegistration(id);
    }

    @Override
    public List<HisRegistration> queryWithMedicalList() {
        return hisRegistrationMapper.queryWithMedicalList();
    }

    @Override
    public List<HisRegistration> queryTheListOfVisitsInProgress() {
        return hisRegistrationMapper.queryTheListOfVisitsInProgress();
    }

    @Override
    public PageInfo<HisRegistration> queryTheListOfCompletedMedicalVisits(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<HisRegistration> hisRegistrationList = hisRegistrationMapper.queryTheListOfCompletedMedicalVisits();
        PageInfo<HisRegistration> pageInfo=new PageInfo<>(hisRegistrationList);
        return pageInfo;
    }

    @Override
    public String receiveAPatientForTreatment(String id) {
        String regId = hisRegistrationMapper.receiveAPatientForTreatment(id);
        return regId;
    }

    @Override
    public int modifyReceiveAPatientForTreatment(String id) {
        return hisRegistrationMapper.modifyReceiveAPatientForTreatment(id);
    }

    @Override
    public int concludePatientVisit(String id) {
        return hisRegistrationMapper.concludePatientVisit(id);
    }


}
